<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
	<div class="page-header">
		<h1>基础设置</h1>
	</div>

	<div class="col-xs-12">
		<form class="form-horizontal" id="school-form">
			<!-- 同步学校 -->
			<?php if(!empty($rmxSchool['school_from'])): ?>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">数据同步：</label>
					<div class="col-sm-6">
						<div class="form-control no-border no-padding-left">
							<a href="javascript:;" id="update-hzy-data"><i class="fa fa-refresh"></i> 同步学校数据</a>
						</div>
					</div>
				</div>
			<?php endif ?>			
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">学校名称：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="school_name" placeholder="请填写学校名称" value="<?=$rmxSchool['school_name']?>"
						<?php if($rmxSchool['school_from']): ?>
							readonly 
						<?php endif ?>
					/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">校区名称：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="campus_name" placeholder="请填写校区名称" value="<?=$campusInfo['campus_name']?>"
						<?php if($rmxSchool['school_from']): ?>
							readonly 
						<?php endif ?>
					/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">刷卡签到：</label>
				<div class="col-sm-6">
					<label class="switch-open-close">
						<input name="enable_card_sign" class="ace ace-switch ace-switch-7" type="checkbox" value="1" <?= $rmxSchool['enable_card_sign'] == 1 ? "checked" : '' ?> />
						<span class="lbl"></span>
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">校训：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="school_motto" placeholder="请填写校训内容" value="<?=$rmxSchool['school_motto']?>" />
				</div>
			</div>

			<!-- 是否开启智能门锁 -->
			<?php if(isset($rmxSchool['school_smart_lock']) && $rmxSchool['school_smart_lock']): ?>
				<!-- <div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">智能门锁 token：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_smart_lock_token" placeholder="" value="<?= isset($smartLockConfigValueArr) ? $smartLockConfigValueArr['token'] : '' ?>" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label no-padding-right">智能门锁 ip：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="school_smart_lock_ip" placeholder="" value="<?= isset($smartLockConfigValueArr) ? $smartLockConfigValueArr['ip'] : '' ?>" />
					</div>
				</div> -->
			<?php endif ?>

			<div class="clearfix">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" type="submit">
						<i class="ace-icon fa fa-check"></i> 提交
					</button>
				</div>
			</div>
		</form>
	</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	
	$(function(){
		// 提交表单
		var form = $("#school-form");
		var submitUrl = "<?=admin_url('setting/save_setting')?>";
		form_submit(form, submitUrl, function(res) {
			tips_alert(res.msg, res.success, function(){
				if(res.success) {
					window.location.href = "<?=admin_url('setting/index')?>";
				}
			});
		})

		// 同步学校信息
		$("#update-hzy-data").click(function(){
			layer.confirm('同步学校信息需要等待一段时间，确定同步数据？', function(){
				var actionUrl = "<?=admin_url('nh/update_nh_school')?>/<?=$rmxSchool['id']?>";
				ajax_get(actionUrl, {}, function(res) {
					// console.log(res);return;
					if(res.success) {
						// 插入日志
						logData = {
							'hideLoading': true,
							'school_id': "<?=$rmxSchool['id']?>"
						};
						$logUrl = "<?=admin_url('setting/save_sync_log_action')?>";
						ajax_post($logUrl, logData);
					}
				});
			})
		})
	})
</script>